package com.shopping.dev.service.impl;

import com.shopping.dev.mapper.CategoryMapper;
import com.shopping.dev.mapper.CategoryMapperCoustom;
import com.shopping.dev.pojo.Category;
import com.shopping.dev.service.CategoryService;
import com.shopping.dev.vo.CategoryVO;
import com.shopping.dev.vo.NewItemsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private CategoryMapperCoustom categoryMapperCoustom;
    @Override
    public List<Category> getCatsRoot() {
        Example example = new Example(Category.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type",1);
        List<Category> categories = categoryMapper.selectByExample(example);
        return categories;
    }

    @Override
    public List<CategoryVO> getSubCat(Integer rootCat) {
        List<CategoryVO> subCats = categoryMapperCoustom.getSubCat(rootCat);
        return subCats;
    }

    @Override
    public List<NewItemsVO> getSixNewItemsLazy(Integer rootCat) {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("rootCatId",rootCat);
        List<NewItemsVO> sixNewItemsLazy = categoryMapperCoustom.getSixNewItemsLazy(paramMap);

        return sixNewItemsLazy;
    }
}
